"""
200
302: 默认允许重定向
	可以通过禁止重定向 截取服务器返回信息, allow_redirects=False
"""
import requests

# import requests
# res = requests.get("https://api.zzzmh.cn/v2/bz/v3/getUrl/02fe45ae880511ebb6edd017c2d2eca221")
# print(res.status_code)
# if res.status_code == 200:
# 	with open("极简壁纸.jpg", "wb") as f:
# 		f.write(res.content)


headers = {
    # "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
    # "referer": "https://bz.zzzmh.cn/"
}

# 拆分重定向
import requests

res = requests.get("https://api.zzzmh.cn/v2/bz/v3/getUrl/02fe45ae880511ebb6edd017c2d2eca221", allow_redirects=False)
if res.status_code == 302:
    location = res.headers['Location']
    print(location)
    img_res = requests.get(location, headers=headers)
    with open("极简壁纸.jpg", "wb") as f:
        f.write(img_res.content)
